<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input v-model="wk" type="text" />
        <ul>
            <li v-show="isLoading">
                <img src="../../assets/img/loading.gif" alt="" srcset="">
            </li>
            <li v-show="!isLoading" v-for="item in arr">{{ item }}</li>
        </ul>
    </div>
    <script type="module">
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        import axios from "../../assets/axios/axios.js"
        createApp({
            data() {
                return {
                    wk:"",
                    isLoading:false,
                    arr:[]
                }
            },
            watch: {
                async wk(nv, ov) {
                    try {
                        this.isLoading = true;
                        let response = await axios.get("http://127.0.0.1:3000/api/search",{
                            params:{
                                // 侦听器 方法中的this 被vue绑定在当前应用的实例对象上
                                // wk:this.wk
                                wk:nv
                            }
                        })
                        this.arr = response.data.list;
                    } catch (error) {
                        alert("请求错误")
                    } finally {
                        this.isLoading = false;
                    }
                }
            },
        }).mount("#app")
    </script>
</body>
</html>